from fastapi import FastAPI
from core.response import register_http_exception

from setting import config
from core.middleware import register_cors, register_process_time, register_trace_id, register_user_name, register_request_record, register_middleware


def create_app() -> FastAPI:
    app = FastAPI(
        title="运维管理平台",
        # description="更多信息查看 https://www.charmcode.cn/article/2020-06-08_vue_mall_api ",
        description="后台API接口",
        version="1.0.0",
        openapi_url=config.OPENAPI_URL,
        docs_url=config.DOCS_URL,
        redoc_url=config.REDOC_URL,
        openapi_tags=config.TAGS_METADATA
    )
    # 注册自定义http异常
    register_http_exception(app)
    # register_exception(app)  # 注册捕获异常信息
    # 跨域设置
    register_cors(app)
    # 注册请求记录
    register_request_record(app)
    # 注册trace_id
    register_trace_id(app)
    # 注册用户名
    register_user_name(app)
    # 注册响应头部添加处理时间
    register_process_time(app)
    # 注册响应头部添加处理时间
    # register_middleware(app)
    return app
